1 using UnityEngine;
2 using
System.Collections;
3
4 public
class PaddleScript : MonoBehaviour
5 {
6
7     
// Use this for initialization
8     
void Start()
9     {
10
11     }
12
13     
// Update is called once per frame
14     
void Update()
15     {
16         
float input;
17
18         
if (Input.touchCount > 0)//touch input
19         {
20             input = Input.touches[
0].position.x >= Screen.width / 2 ? 1f : -1f;
21         }
22         
else//keyboard input
23         {
24             input = Input.GetAxis(
"Horizontal");
25         }
26
27         transform.Translate(
new Vector2(input * speed * Time.deltaTime, 0));
28         
float currentX = Mathf.Clamp(transform.position.x, LeftBlockTransform.position.x + 1, RightBLockTransform.position.x - 1);
29         transform.position =
new Vector3(currentX, transform.position.y, transform.position.z);
30     }
31
32     
public Transform LeftBlockTransform, RightBLockTransform;
33     
public float speed = 50;
34      
35 }


Use this for initialization

Update is called once per frame

if (Input.touchCount > 0)touch input

elsekeyboard input




Trò chơi xếp gạch đơn giản 7.088 lượt xem

Gõ tìm kiếm nhanh...